package com;

import java.io.IOException;
import java.util.HashMap;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @web.servlet name="ValidateServlet"
 * @web.servlet-mapping url-pattern="/validate"
 */

public class ValidateServlet extends HttpServlet{

	private static final long serialVersionUID = -8869296662389030141L;
	
	private ServletContext context;
	private HashMap<String, String> users = new HashMap<String, String>();
	
	public void init(ServletConfig config)throws ServletException {
		super.init(config);
		this.context = config.getServletContext();
		users.put("charith", "account data");
		users.put("test", "account data");
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String targetId = request.getParameter("id");
		System.out.println(targetId);
		if(targetId != null && users.containsKey(targetId.trim())){
			response.setContentType("text/xml");
			response.setHeader("Cache-Control", "no-cache");
			response.getWriter().write("<message>valid</message>");
		}else {
            response.setContentType("text/xml");
            response.setHeader("Cache-Control", "no-cache");
            response.getWriter().write("<message>invalid</message>"); 
        }
	}
	
	
}
